<script setup lang="ts">
import { useRoute, useRouter } from 'vue-router'
import { defineProps, defineEmits } from 'vue';
const router = useRouter()
const { emit } = defineEmits(['click-left','click-right']);
const props = defineProps({
  title: {
    type: String,
    default: '标题',
  },
  leftArrow: {
    type: Boolean,
    default: true
  },
  isWhiteArrow: {
    type: Boolean,
    default: false
  },
  backCallback:{
    type:Boolean,
    default :false
  }
});
const handleLeftClick = () => {
  if(props.backCallback){
    emit("click-left")
    return
  }else{
    router.go(-1);
  }
};
</script>
<template>
  <div class="nav-header">
    <div class="nav-header_back">
      <slot name="left">
        <div v-if="leftArrow" class="left-icon"  @click="handleLeftClick" >
          <img v-if="!isWhiteArrow" src='@/assets/images/icon/icon-back-black.png' />
          <img v-if="isWhiteArrow" src='@/assets/images/icon/icon-back-white.png' />
        </div>
      </slot>
    </div>
    <slot name="middle">
      <div class="nav-header_center">{{ props.title }}</div>
    </slot>
    <div class="nav-header_right">
      <slot name="right"></slot>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.nav-header {
  width: 100%;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  z-index: 888;
  transition: all, 0.5s;
  background: transparent;
  .nav-header_back {
    width: 15%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    height: 100%;
    .left-icon {
      height: 100%;
      width: 30px;
      display: flex;
      align-items: center;
      flex-direction: column;
      justify-content: center;
      color: rgb(216, 202, 202);
      img {
        width: 10px;
        height: 10px;
        display: block;
      }
    }
  }
  .nav-header_center {
    flex: 1;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    font-size: 9px;
    font-weight: bold;
    height: 100%;
    color: #2C2C2C;
    text-align: center;
  }
  .nav-header_right {
    width: 15%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
  }
}
</style>

